export const BASEURL = "https://f.kjdll.cn:9999/api/v1";

const url = {
    zzjgSearch: BASEURL + "/zzjg/index",
    roleSearch:  BASEURL + "/role/index",
    webReg:  BASEURL + "/public/webUserReg",
}

axios.defaults.headers.post['Content-Type'] = 'application/json';

export const Post = (url, params) => {
    let token = localStorage.getItem('token');
    //console.log("token:",token);
    //console.log("BASEURL:",BASEURL);
    return new Promise((resolve, reject) => {
        //取得项目资料
        axios({
            method: 'post',
            url: url,
            params: params,
            responseType: 'json',
            headers: {
                'Content-Type': 'application/json',//multipart/form-data,application/json
            },
            headers: {
                'X-Requested-With': 'XMLHttpRequest',
                'XX-Device-Type': 'web',
                'Authorization': token,
            },
        }).then(function (res) {
            if (res.data.code == 1) {
                resolve(res.data);
            }else{
                reject(res.data);
            }
        }).catch((res) => {
            reject(res.data);
        });
    });
}

export const zzjgSearch = (params) => {
    return new Promise((resolve, reject) => {
        Post(url.zzjgSearch, params).then((res) => {
            resolve(res);
        }).catch((res) => {
            reject(res);
        });
    });

}

export const roleSearch = (params) => {
    return new Promise((resolve, reject) => {
        Post(url.roleSearch, params).then((res) => {
            resolve(res);
        }).catch((res) => {
            reject(res);
        });
    });

}

export const webReg = (params) => {
    return new Promise((resolve, reject) => {
        Post(url.webReg, params).then((res) => {
            resolve(res);
        }).catch((res) => {
            reject(res);
        });
    });

}

export const formatDate = function unixtimetostr1(unixtime) {
    var dateTime = new Date(parseInt(unixtime) * 1000)
    var year = dateTime.getFullYear();
    var month = dateTime.getMonth() + 1;
    var day = dateTime.getDate();
    var timeSpanStr = year + '-' + month + '-' + day;
    return timeSpanStr;
}

export function unixtimetostr(unixtime) {
    var dateTime = new Date(parseInt(unixtime) * 1000)
    var year = dateTime.getFullYear();
    var month = dateTime.getMonth() + 1;
    var day = dateTime.getDate();
    var timeSpanStr = year + '-' + month + '-' + day;
    return timeSpanStr;
}

export default{
    BASEURL, Post,
    zzjgSearch,roleSearch,webReg,
    formatDate,unixtimetostr
}